package com.example.backspring.controller;

import com.alibaba.fastjson.JSONArray;
import com.example.backspring.Service.LearnService;
import com.example.backspring.config.Message;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin(origins = {"http://localhost:8095",
        "http://localhost:5173",
        "http://localhost:5174",
        "http://192.168.18.155:8989",
        "http://192.168.18.155:8989/learn/fuxi","http://192.168.18.155:8989/learn/xuewan"})
@RestController
@RequestMapping("/learn")
@Tag(name = "学习管理", description = "获取和管理学习记录")
public class Learn {
    @Resource
    private LearnService learnService;

    // 获取复习记录
    @Operation(summary = "获取复习记录", description = "获取复习记录数据")
    @PostMapping("/fuxi")
    public Message getFuxi() {
        Message res = learnService.getFuxi();
        return res;
    }

    // 获取学习记录
    @Operation(summary = "获取学习记录", description = "获取学习记录数据")
    @PostMapping("/xuewan")
    public Message updateXue() {
        Message res = learnService.getXuewan();
        return res;
    }

    // 新增学习记录
    @Operation(summary = "新增学习记录", description = "添加新的学习记录")
    @PostMapping("/xue")
    public Message addXue(String nr) {
        Message res = learnService.addLearn(nr);
        return res;
    }

    // 修改学习记录
    @Operation(summary = "修改学习记录", description = "更新学习记录数据")
    @PostMapping("/zuijia")
    public Message zuijia(String nr) {
        Message res = learnService.zuijia(nr);
        return res;
    }
}
